package com.zb.emq;

import lombok.extern.slf4j.Slf4j;
import org.eclipse.paho.client.mqttv3.IMqttDeliveryToken;
import org.eclipse.paho.client.mqttv3.MqttCallback;
import org.eclipse.paho.client.mqttv3.MqttMessage;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class EmqMsgProcess implements MqttCallback {
    @Override
    public void connectionLost(Throwable throwable) {
        log.info("重新建立连接...");
    }

    @Override
    public void messageArrived(String topic, MqttMessage mqttMessage) throws Exception {
        log.info("接收mqtt服务器发送的主题：" + topic);
        String payload = new String(mqttMessage.getPayload());
        System.out.println("接收的数据是:" + payload);
    }

    @Override
    public void deliveryComplete(IMqttDeliveryToken iMqttDeliveryToken) {
        log.info("断开连接");
    }
}
